﻿using B.S.Filtration.Domain;
using B.S.Filtration.ErrorCode;
using B.S.Filtration.Read.Api.Application.Command.ProcessCommand;
using MediatR;
using SqlSugar;

namespace B.S.Filtration.Read.Api.Application.CommandHander.ProcessHandler
{
    public class GetBYIdCraftsmanshipCommandHandler : IRequestHandler<GetBYIdCraftsmanshipCommand, APIResult<List<Craftsmanship>>>
    {
        private readonly ISqlSugarClient db;

        public GetBYIdCraftsmanshipCommandHandler(ISqlSugarClient db)
        {
            this.db = db;
        }

        public async Task<APIResult<List<Craftsmanship>>> Handle(GetBYIdCraftsmanshipCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<Craftsmanship>> result = new APIResult<List<Craftsmanship>>();
            result.code = APIResultCode.success;
            result.msg = "查询成功";

            var list = await db.Queryable<Craftsmanship>().Where(p => p.CraftsmanshipId == request.CraftsmanshipId).ToListAsync();

            result.data = list;
            return await Task.FromResult(result);
        }
    }
}
